package com.aspose.cells;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

class zcfc extends zcfd {
   private HashMap e = new HashMap();
   private boolean f = false;
   private byte[] g;
   private byte[] h;
   private byte[] i;
   private ArrayList j;
   private static final com.aspose.cells.b.c.a.za k = new com.aspose.cells.b.c.a.za(new String[]{"#REF", "#REF!"});

   zcfc(WorksheetCollection var1) {
      super(var1);
      Iterator var2 = var1.iterator();

      while(var2.hasNext()) {
         Worksheet var3 = (Worksheet)var2.next();
         byte[] var4 = new byte[3];
         System.arraycopy(com.aspose.cells.b.a.zc.a(var3.l()), 0, var4, 1, 2);
         this.e.put(var3.getName().toUpperCase(), var4);
      }

      this.g = new byte[]{1, 2};
      this.h = new byte[]{3};
      this.i = new byte[]{2};
      this.j = new ArrayList();
   }

   int[] a(zabd var1, String var2) {
      this.j.clear();
      this.f = true;
      int[] var3 = new int[2];
      int var4 = var2.indexOf("!");
      if (var4 != -1) {
         String var5 = var2.substring(0, 0 + var4);
         var2 = var2.substring(var4 + 1);
         String var6 = var2.toUpperCase();
         this.b(var5);
         this.a(var2, var2);
      } else {
         com.aspose.cells.b.a.a.ze.a(this.j, (Object)(new byte[]{-1, -1}));
         this.a(var2, var2);
         var3[0] = -1;
      }

      this.a((byte[])null, 0);
      this.f = false;
      return var3;
   }

   private void a(String var1, String var2) {
      int var3 = 4;
      int var4 = Name.e(var1);
      byte[] var5 = null;
      if (var4 == -1) {
         var5 = zco.a(var2);
         var3 += var5.length;
      }

      byte[] var6 = new byte[var3];
      var6[0] = (byte)(var4 + 1);
      if (var5 != null) {
         zco.a(var6, 1, var5, var2);
      }

      com.aspose.cells.b.a.a.ze.a(this.j, (Object)var6);
   }

   int[] a(String var1) {
      this.j.clear();
      this.b(var1);
      return new int[4];
   }

   byte[] a(zabd var1, String var2, int var3, int var4, int var5, String var6, int var7, int var8) {
      this.j.clear();
      this.a(var1, var2);
      byte[] var9 = new byte[7];
      switch(var8) {
      case 32:
         var9[0] = 57;
         break;
      case 64:
         var9[0] = 89;
         break;
      case 96:
         var9[0] = 121;
      }

      return var9;
   }

   private void b(String var1) {
      if (var1.length() != 0) {
         String var2 = zyn.b(var1);
         String var3 = var2.toUpperCase();
         switch(k.a(var2)) {
         case 0:
         case 1:
            com.aspose.cells.b.a.a.ze.a(this.j, (Object)this.g);
            com.aspose.cells.b.a.a.ze.a(this.j, (Object)this.h);
            return;
         default:
            Object var4 = this.e.get(var3);
            if (var4 != null) {
               com.aspose.cells.b.a.a.ze.a(this.j, (Object)this.g);
               com.aspose.cells.b.a.a.ze.a(this.j, var4);
               if (!this.f) {
                  com.aspose.cells.b.a.a.ze.a(this.j, (Object)this.i);
               }

            } else {
               int var5 = var2.lastIndexOf(91);
               if (var5 != -1) {
                  String var10 = null;
                  int var11 = var2.lastIndexOf(93);
                  if (var5 != 0) {
                     var10 = var2.substring(0, 0 + var5) + var2.substring(var5 + 1, var5 + 1 + (var11 - var5 - 1));
                  } else {
                     var10 = var2.substring(1, 1 + (var11 - 1));
                  }

                  var2 = var2.substring(var11 + 1);
                  this.b(var10, var2);
               } else {
                  int var6 = var2.indexOf(":");
                  if (var6 != -1 && var6 + 1 < var2.length() && var2.charAt(var6 + 1) != '\\' && var2.charAt(var6 + 1) != '/') {
                     String[] var7 = com.aspose.cells.b.a.zv.d(var3, ':');
                     if (var7.length != 2) {
                        throw new CellsException(5, "Invalid formula.");
                     }

                     Object var8 = this.e.get(var7[0]);
                     Object var9 = this.e.get(var7[1]);
                     if (var8 == null || var9 == null) {
                        throw new CellsException(5, "Invalid formula.");
                     }

                     com.aspose.cells.b.a.a.ze.a(this.j, (Object)this.g);
                     com.aspose.cells.b.a.a.ze.a(this.j, var8);
                     if (!this.f) {
                        com.aspose.cells.b.a.a.ze.a(this.j, var9);
                     }
                  } else {
                     this.b(var2, (String)null);
                  }
               }

            }
         }
      }
   }

   private void b(String var1, String var2) {
      String var3 = zbqg.a(var1, 0);
      byte[] var4 = zco.a(var3);
      int var5 = var4.length + 3;
      byte[] var6 = null;
      Object var7 = null;
      Object var8 = null;
      Object var9 = null;
      if (var2 != null) {
         int var10 = var1.indexOf(58);
         if (var10 == -1) {
            var6 = zco.a(var2);
         }
      }

      if (var6 != null) {
         var5 += var6.length + 4;
      } else {
         var5 += 4;
         if (!this.f) {
            if (var7 == null) {
               ++var5;
            } else {
               var5 += ((Object[])var7).length + 4;
            }
         }
      }

      byte[] var12 = new byte[var5];
      byte var11 = 0;
      int var13 = var11 + zco.a(var12, var11, var4, var3);
      int var10000;
      if (var6 != null) {
         var12[var13] = 1;
         ++var13;
         var10000 = var13 + zco.a(var12, var13, var6, (String)var8);
      } else {
         var12[var13] = 1;
         ++var13;
         var13 += 3;
         if (!this.f) {
            if (var7 == null) {
               var12[var13] = this.i[0];
               ++var13;
            } else {
               var12[var13] = 1;
               ++var13;
               var10000 = var13 + zco.a(var12, var13, (byte[])var7, (String)var9);
            }
         }
      }

   }

   void a(byte[] var1, int var2) {
      com.aspose.cells.b.a.a.ze.a(this.b, (Collection)this.j);

      byte[] var4;
      for(Iterator var3 = this.j.iterator(); var3.hasNext(); this.a += var4.length) {
         var4 = (byte[])var3.next();
      }

      this.j.clear();
   }
}
